package com.robert.custombehavior.adpatper

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView

import com.robert.custombehavior.R

class MyRvAdapter(private val context: Context) : RecyclerView.Adapter<MyRvAdapter.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        val view = inflater.inflate(R.layout.item_rv, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.tv.text = "第" + position + "条数据"
    }

    override fun getItemCount(): Int {
        return 40
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        internal var tv: TextView

        init {
            tv = itemView.findViewById<View>(R.id.tv) as TextView
        }
    }

}